﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using ZLDC.Common.Estate;
using System.Data;

namespace ZLDC.DAL.Estate
{
    public class DayReportDAL
    {
        public static void p_dayReport_insert(string reportDate, int addDeptId, string addDept, int addUserId, string addUser, string content, string adviseandplan, string title, out string outmsg, out int newid, _Database db)
        {
            List<SqlParameter> parms = new List<SqlParameter>();

            parms.Add(new SqlParameter("@reportDate", reportDate));
            parms.Add(new SqlParameter("@addDeptId", addDeptId));
            parms.Add(new SqlParameter("@addDept", addDept));
            parms.Add(new SqlParameter("@addUserId", addUserId));
            parms.Add(new SqlParameter("@addUser", addUser));
            parms.Add(new SqlParameter("@content", content));
            parms.Add(new SqlParameter("@adviseandplan", adviseandplan));
            parms.Add(new SqlParameter("@title", title));


            SqlParameter pOutmsg = new SqlParameter("@outmsg", SqlDbType.VarChar, 256);
            pOutmsg.Direction = ParameterDirection.Output;
            parms.Add(pOutmsg);

            SqlParameter pNewid = new SqlParameter("@newid", SqlDbType.Int, 4);
            pNewid.Direction = ParameterDirection.Output;
            parms.Add(pNewid);
            SqlParameter pRetval = new SqlParameter("@retval", SqlDbType.Int, 4);
            pRetval.Direction = ParameterDirection.ReturnValue;
            parms.Add(pRetval);


            db.execute_procedure("p_dayReport_insert", parms);

            outmsg = (pOutmsg.Value == System.DBNull.Value) ? "" : Convert.ToString(pOutmsg.Value);
            newid = (pNewid.Value == System.DBNull.Value) ? 0 : Convert.ToInt32(pNewid.Value);

            int retval = (pRetval.Value == System.DBNull.Value) ? 0 : Convert.ToInt32(pRetval.Value);

        }

        public static void p_dayReport_save(int ID, string reportDate, int addDeptId, string addDept, int addUserId, string addUser, string content, string adviseandplan, int readflag, string title, out string outmsg, out int newid, _Database db)
        {
            List<SqlParameter> parms = new List<SqlParameter>();

            parms.Add(new SqlParameter("@ID", ID));
            parms.Add(new SqlParameter("@reportDate", reportDate));
            parms.Add(new SqlParameter("@addDeptId", addDeptId));
            parms.Add(new SqlParameter("@addDept", addDept));
            parms.Add(new SqlParameter("@addUserId", addUserId));
            parms.Add(new SqlParameter("@addUser", addUser));
            parms.Add(new SqlParameter("@content", content));
            parms.Add(new SqlParameter("@adviseandplan", adviseandplan));
            parms.Add(new SqlParameter("@readflag", readflag));
            parms.Add(new SqlParameter("@title", title));

            SqlParameter pOutmsg = new SqlParameter("@outmsg", SqlDbType.VarChar, 256);
            pOutmsg.Direction = ParameterDirection.Output;
            parms.Add(pOutmsg);

            SqlParameter pNewid = new SqlParameter("@newid", SqlDbType.Int, 4);
            pNewid.Direction = ParameterDirection.Output;
            parms.Add(pNewid);
            SqlParameter pRetval = new SqlParameter("@retval", SqlDbType.Int, 4);
            pRetval.Direction = ParameterDirection.ReturnValue;
            parms.Add(pRetval);


            db.execute_procedure("p_dayReport_save", parms);

            outmsg = (pOutmsg.Value == System.DBNull.Value) ? "" : Convert.ToString(pOutmsg.Value);
            newid = (pNewid.Value == System.DBNull.Value) ? 0 : Convert.ToInt32(pNewid.Value);

            int retval = (pRetval.Value == System.DBNull.Value) ? 0 : Convert.ToInt32(pRetval.Value);

        }
        public static DataTable p_dayReport_list_table(int page, int pagesize, string condition, ref int total, _Database db)
        {
            List<SqlParameter> parms = new List<SqlParameter>();

            parms.Add(new SqlParameter("@page", page));
            parms.Add(new SqlParameter("@pagesize", pagesize));
            parms.Add(new SqlParameter("@condition", condition));

            SqlParameter pTotal = new SqlParameter("@total", SqlDbType.Int, 4);
            pTotal.Direction = ParameterDirection.InputOutput;
            pTotal.Value = total;
            parms.Add(pTotal);
            SqlParameter pRetval = new SqlParameter("@retval", SqlDbType.Int, 4);
            pRetval.Direction = ParameterDirection.ReturnValue;
            parms.Add(pRetval);

            DataTable dt = null;
            dt = db.GetDataTable("p_dayReport_list", parms);

            total = (pTotal.Value == System.DBNull.Value) ? 0 : Convert.ToInt32(pTotal.Value);

            int retval = (pRetval.Value == System.DBNull.Value) ? 0 : Convert.ToInt32(pRetval.Value);

            return dt;
        }

        public static DataSet SelectDayReportListById(int id, _Database db)
        {
            DataSet ds = null;

            try
            {

                string sql = "select * from t_dayReport where id=" + id + "";
                ds = db.Query(sql);

            }
            catch { }
            finally
            {
                db.close();
            }
            return ds;
        }

    }
}
